#!/bin/bash
log_file=transmission.log
ip_list=ip.txt
source_file=/data/soft/OpsInsp-exporter.tar.gz
target=/home/opskingdee
user=opskingdee
passwd=Cosmic@2024
echo "------------(begin)------------" >$log_file
ip_num=`cat $ip_list | wc -l`
for (( i=1; i<=$ip_num; i++ ))
do
    ip=`cat $ip_list | head -$i | tail -1`
    echo $ip
sleep 1
    /usr/bin/expect <<EOF
spawn scp -r $source_file $user@$ip:$target
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$passwd\r" }
}
"*assword:"
{
send "$passwd\r"
}
}
expect eof
EOF
    if [ $? -eq 0 ];then
        echo "$ip: ERROR" >> $log_file
    else 
        echo "$ip: accessue" >> $log_file
    fi
    echo '------------(end)------------' >>$log_file
done